package com.atguigu.flink.streamapi.trans;

import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * Created by Smexy on 2023/1/13
 *
 *  多流操作。
 *      多个流
 */
public class Demo4_Union
{
    public static void main(String[] args) {

        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        env.setParallelism(1);

        //unino为合并，将多个同类型的流合并为1个流
        DataStreamSource<Integer> ds1 = env.fromElements(1, 2, 3);
        DataStreamSource<Integer> ds2 = env.fromElements(11, 22, 33);
        DataStreamSource<Integer> ds3 = env.fromElements(111, 222, 333);
        DataStreamSource<String> ds4 = env.fromElements("11", "22", "33");

        //同流合污
        DataStream<Integer> ds5 = ds1.union(ds2, ds3);
        ds5.print();

        try {
            env.execute();
        } catch (Exception e) {
            e.printStackTrace();
        }


    }
}
